#include "../../h/apue.h"
#include <fcntl.h>

int main(int argc, char ** argv)
{
    struct stat fbuf;

    if (argc != 2)
        err_quit("Usage: a.out <pathname>");

    lstat(argv[1], &fbuf);
    printf("user id: %d. group id: %d.\n", fbuf.st_uid, fbuf.st_gid);

    if (access(argv[1], F_OK) < 0)
        err_quit("file %s not exist.", argv[1]);

    if (faccessat(AT_FDCWD, argv[1], R_OK, 0/*AT_EACCESS*/) < 0)
        err_ret("access error for %s.", argv[1]);
    else
        printf("read access OK\n");
    if (open(argv[1], O_RDONLY) < 0)
        err_ret("open error for %s.", argv[1]);
    else
        printf("open for reading OK.\n");

    return 0;

}
